package com.ctrip.corp.obt.shard.constants;

import lombok.Getter;

/**
 * 这里决定了你当前的数据源是属于什么类型，读/写/读写/灰度
 *
 * @author x.shen
 * @since 2024/2/4
 */
@Getter
public enum DbRole {
    READ("read", "只读"),
    WRITE("write", "只写"),
    READ_WRITE("readWrite", "读写");

    private final String code;

    private final String desc;

    DbRole(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static DbRole getDbRoleByCode(String code) {
        for (DbRole dbRole : DbRole.values()) {
            if (dbRole.getCode().equalsIgnoreCase(code)) {
                return dbRole;
            }
        }
        return READ_WRITE;
    }
}
